<?php

namespace App\Http\Resources;

class MessageResource
{

    /**
     * 格式化输出
     * @param $data
     * @return array
     */
    public function formatArray($data) : array
    {

        $returnData = [];
        foreach ($data['list'] as $k => $v) {
            $returnData[$k] = [
                'id' => $v['id'],
                'user_id' => $v['user_id'],
                'content' => $v['content'],
                'created_at' => $v['created_at'],
                'from_user_id' => $v['from_user_id'],
                'from_user_name' => $v['from_user']['name'],
                'from_user_head_img' => $v['from_user']['http_head_img'],
                'topic_id' => $v['relation_id'],
                'topic' => $v['topic']['title'],
            ];
        }

        return ['list' => $returnData, 'total' => $data['total']];
    }
}
